<template>
  <div class="app-container">
    <div v-show="type === 0 || type === 2">
      <el-row>
        <el-col :span="24">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="98px"
          >
            <el-form-item label="商机名称" prop="businessName">
              <el-input
                v-model="queryParams.businessName"
                placeholder="请输入商机名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="客户名称" prop="enterpriseName">
              <el-input
                v-model="queryParams.enterpriseName"
                placeholder="请输入客户名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="商机类型" prop="businessType">
              <el-select
                v-model="queryParams.businessType"
                placeholder="请选择商机类型"
              >
                <el-option
                  v-for="dict in dict.type.business_classify"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商机来源" prop="businessSource">
              <el-select
                v-model="queryParams.businessSource"
                placeholder="请选择商机类型"
              >
                <el-option
                  v-for="dict in dict.type.business_source"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商机状态" prop="businessState">
              <el-select
                v-model="queryParams.businessState"
                placeholder="请选择商机状态"
              >
                <el-option
                  v-for="dict in dict.type.business_state"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="最新操作时间">
              <el-date-picker
                v-model="dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>

          <el-row :gutter="10" class="mb8">
            <right-toolbar
              :showSearch.sync="showSearch"
              @queryTable="getList"
              :columns="columns"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            height="400"
            :data="informationList"
            @selection-change="handleSelectionChange"
            :row-style="{ height: '30px' }"
            border
            :cell-style="{ padding: '0px' }"
            :row-class-name="tableRowClassName"
            highlight-current-row
          >
            <el-table-column type="selection" width="45" align="center" />
            <el-table-column
              label="序号"
              type="index"
              align="center"
              prop="index"
              :index="indexMethod"
            ></el-table-column>
            <el-table-column
              label="审核状态"
              align="center"
              prop="approvalResults"
              width="100"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.approvalResults === '同意'" style="color: green;">{{ scope.row.approvalResults }}</span>
                <span v-else-if="scope.row.approvalResults === '不同意'" style="color: red;">{{ scope.row.approvalResults }}</span>
                <span v-else>未审核</span>
              </template>
            </el-table-column>
            <el-table-column label="报价时间" align="center" prop="operateTime" width="85"
                             :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.operateTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="报价人"
              align="center"
              prop="operateName"
              :show-overflow-tooltip="true"
              width="150"
            />
            <el-table-column
              label="客户名称"
              align="center"
              prop="companyName"
              :show-overflow-tooltip="true"
              width="150"
            />
            <el-table-column label="商机名称" align="center" prop="businessName" :show-overflow-tooltip="true"  width="150" />
            <el-table-column label="预成交时间" align="center" prop="transactionTime" width="120"
                             :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.transactionTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="预成交金额" align="center" prop="transactionAmount" :show-overflow-tooltip="true"  width="120">
              <template slot-scope="scope">
                <span v-if="scope.row.transactionAmount !== null">{{ scope.row.transactionAmount }}万元</span>
                <span v-else>无</span>
              </template>
            </el-table-column>
            <el-table-column
              label="版本"
              align="center"
              prop="version"
              :show-overflow-tooltip="true"
              width="60"
            />
            <el-table-column label="报价单附件" align="center" prop="uploadFile">
              <template slot-scope="scope">
                <el-button v-if="scope.row.url != null && scope.row.url != ''" @click="handlePictureCardPreview(scope.row.uploadFile, businessCode)" size="small"
                           type="text">附件</el-button>
                <el-button size="small" v-else type="text">无附件</el-button>
              </template>
            </el-table-column>

<!--            <el-table-column-->
<!--              label="创建时间"-->
<!--              align="center"-->
<!--              prop="creationTime"-->
<!--              width="100"-->
<!--              v-if="columns[0].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--              sortable-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <span>{{-->
<!--                  parseTime(scope.row.creationTime, "{y}-{m}-{d}")-->
<!--                }}</span>-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="最新操作时间"-->
<!--              align="center"-->
<!--              prop="followTime"-->
<!--              v-if="columns[18].visible"-->
<!--              width="100"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="商机名称"-->
<!--              align="center"-->
<!--              prop="businessName"-->
<!--              v-if="columns[1].visible"-->
<!--              width="180"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="客户名称"-->
<!--              align="center"-->
<!--              prop="enterpriseName"-->
<!--              v-if="columns[2].visible"-->
<!--              width="180"-->
<!--              :show-overflow-tooltip="true"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <a-->
<!--                  @click="handleToEnterprise(scope.row)"-->
<!--                  class="hyperlink"-->
<!--                  style="color: #46a6ff"-->
<!--                >-->
<!--                  {{ scope.row.enterpriseName }}-->
<!--                </a>-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="商机状态"-->
<!--              align="center"-->
<!--              prop="businessState"-->
<!--              v-if="columns[3].visible"-->
<!--              width="90"-->
<!--              :show-overflow-tooltip="true"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <dict-tag-->
<!--                  :options="dict.type.business_state"-->
<!--                  :value="scope.row.businessState"-->
<!--                />-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="商机类型"-->
<!--              align="center"-->
<!--              prop="businessType"-->
<!--              v-if="columns[4].visible"-->
<!--              width="90"-->
<!--              :show-overflow-tooltip="true"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <dict-tag-->
<!--                  :options="dict.type.business_classify"-->
<!--                  :value="scope.row.businessType"-->
<!--                />-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="商机来源"-->
<!--              align="center"-->
<!--              prop="businessSource"-->
<!--              v-if="columns[5].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <dict-tag-->
<!--                  :options="dict.type.business_source"-->
<!--                  :value="scope.row.businessSource"-->
<!--                />-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="联系人姓名"-->
<!--              align="center"-->
<!--              prop="contacts"-->
<!--              width="100"-->
<!--              v-if="columns[6].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="联系人电话"-->
<!--              align="center"-->
<!--              prop="telephone"-->
<!--              width="110"-->
<!--              v-if="columns[7].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="联系人职位"-->
<!--              align="center"-->
<!--              prop="position"-->
<!--              width="100"-->
<!--              v-if="columns[8].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="商机提供人"-->
<!--              align="center"-->
<!--              prop="businessProvider"-->
<!--              width="100"-->
<!--              v-if="columns[9].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="预计成交时间"-->
<!--              align="center"-->
<!--              prop="expectedDate"-->
<!--              width="120"-->
<!--              v-if="columns[10].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <span>{{-->
<!--                  parseTime(scope.row.expectedDate, "{y}-{m}-{d}")-->
<!--                }}</span>-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="创建人"-->
<!--              align="center"-->
<!--              prop="creationNickName"-->
<!--              v-if="columns[11].visible"-->
<!--              width="100"-->
<!--              :show-overflow-tooltip="true"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="跟单阶段"-->
<!--              align="center"-->
<!--              prop="trackingStage"-->
<!--              v-if="columns[12].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <dict-tag-->
<!--                  :options="dict.type.tracking_stage"-->
<!--                  :value="scope.row.trackingStage"-->
<!--                />-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column-->
<!--              label="开发经理"-->
<!--              align="center"-->
<!--              prop="developmentManagerNickName"-->
<!--              v-if="columns[14].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--              width="100"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="业务经理"-->
<!--              align="center"-->
<!--              prop="businessManagerNickName"-->
<!--              v-if="columns[15].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--              width="100"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="协作人"-->
<!--              align="center"-->
<!--              prop="collaboratorNickName"-->
<!--              v-if="columns[16].visible"-->
<!--              :show-overflow-tooltip="true"-->
<!--              width="100"-->
<!--            />-->
<!--            <el-table-column-->
<!--              label="附件"-->
<!--              align="center"-->
<!--              v-if="columns[17].visible"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <el-button-->
<!--                  @click.stop="queryUploadFile(scope.row.businessId)"-->
<!--                  size="small"-->
<!--                  v-if="scope.row.url != null && scope.row.url !== ''"-->
<!--                  type="text"-->
<!--                  >附件</el-button-->
<!--                >-->
<!--                <el-button size="small" v-else type="text">无附件</el-button>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
              fixed="right"
              width="150"
              style="background-color: red"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-user"
                  @click.stop="approveQuotation(scope.row)"
                  title="审核"
                  v-if="scope.row.approvalId == userId && scope.row.approvalResults == null"
                ></el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click.stop="viewQuotation(scope.row)"
                  title="查看"
                ></el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-col>
      </el-row>
    </div>
    <el-dialog :visible.sync="dialogVisible" append-to-body>
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
    <el-dialog :visible.sync="dialogVisiblePdf" append-to-body>
      <pdf
        v-for="item in pageTotal"
        :src="pdfUrl"
        :key="item"
        :page="item"
      ></pdf>
    </el-dialog>
    <el-dialog
      :title="titleQuotation"
      :visible.sync="openQuotation"
      width="800px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rulesQuotation"
        label-width="120px"
      >
        <el-row>
          <el-row>
          <el-col :span="8" style="height: 55px">
            <el-form-item
              label="商机名称"
              prop="businessName"
              label-width="80px"
            >
              <el-input
                v-model="form.businessName"
                placeholder="请输入商机名称" disabled="true"
                style="width: 260px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="14" style="height: 55px">
            <el-form-item
              label="客户名称"
              prop="companyName"
              label-width="230px"
            >
              <el-input
                v-model="form.companyName"
                placeholder="请输入公司名称"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="联系人" prop="contacts" label-width="80px">
                <el-select
                  v-model="form.contacts"
                  placeholder="请选择联系人"
                  style="width: 260px"
                  :disabled="disabled"
                >
                  <el-option
                    v-for="person in contactsList"
                    :key="person.id"
                    :label="person.name"
                    :value="person.name"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="14" style="height: 55px">
              <el-form-item label="联系电话" prop="unit" label-width="230px">
                <el-select
                  v-model="form.unit"
                  placeholder="请选择联系电话"
                  :disabled="disabled"
                  style="width: 215px"
                >
                  <el-option
                    v-for="person in contactsList"
                    :key="person.id"
                    :label="person.phone"
                    :value="person.phone"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="报价时间" prop="operateTime" label-width="80px">
                <el-date-picker
                  clearable
                  v-model="form.operateTime"
                  type="date"
                  :disabled="disabled"
                  value-format="yyyy-MM-dd"
                  :picker-options="{ disabledDate: dateOptions }"
                  placeholder="请选择报价时间"
                  :editable="false"
                  style="width: 260px"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="14" style="height: 55px">
              <el-form-item
                label="报价人"
                prop="operateName"
                label-width="230px"
              >
                <el-input
                  v-model="form.operateName"
                  placeholder="请输入报价人"
                  disabled
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="预成交时间" prop="transactionTime" label-width="80px">
                <el-date-picker
                  clearable
                  v-model="form.transactionTime"
                  type="date"
                  :disabled="disabled"
                  value-format="yyyy-MM-dd"
                  :picker-options="{ disabledDate: dateOptions }"
                  placeholder="请选择预成交时间"
                  :editable="false"
                  style="width: 260px"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="14" style="height: 55px">
              <el-form-item
                label="预成交金额"
                prop="transactionAmount"
                label-width="230px"
              >
                <el-input
                  v-model="form.transactionAmount"
                  placeholder="请输入预成交金额"
                  :disabled="disabled"
                >
                  <template #append>万元</template></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22" style="height: 92px">
              <el-form-item
                label="售后服务"
                prop="afterService"
                label-width="80px"
              >
                <el-input
                  v-model="form.afterService"
                  type="textarea"
                  :rows="3"
                  placeholder=" 请输入售后服务内容"
                  :disabled="disabled"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22" style="height: 92px">
              <el-form-item label="温馨提示" prop="tips" label-width="80px">
                <el-input
                  v-model="form.tips"
                  type="textarea"
                  :rows="3"
                  placeholder=" 请输入温馨提示内容"
                  :disabled="disabled"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 52px">
              <el-form-item label="审批人" prop="approvalName" label-width="80px">
                <el-input
                  :value="form.approvalDisplayName || form.approvalName"
                  placeholder="请输入审批人"
                  :disabled="disabled"
                  readonly
                />
              </el-form-item>
            </el-col>
            <el-col :span="14" v-if="isShow" style="height: 52px">
              <el-form-item
                label="审批结果"
                prop="approvalResults"
                label-width="230px"
              >
                <el-radio-group
                  v-model="form.approvalResults"
                  style="margin-left: 40px"
                  :disabled="result"
                >
                  <el-radio label="同意"></el-radio>
                  <el-radio label="不同意"></el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="isShow">
            <el-col :span="22">
              <el-form-item
                label="审批信息"
                prop="approvalInformation"
                label-width="80px"
              >
                <el-input
                  v-model="form.approvalInformation"
                  type="textarea"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  placeholder=" 请输入审批信息"
                  :disabled="result"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
      </el-form>
      <div style="text-align: center">
        <el-button type="primary" @click="submitFormQuotation" v-if="isSave"
          >保 存</el-button
        >
        <el-button @click="cancelQuotation">关 闭</el-button>
      </div>
    </el-dialog>
    <!--    附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="UploadCode"  v-if="openFileList"></UploadFile>
    </el-dialog>
  </div>
</template>
<script>
import {
  listInformationReview
} from "@/api/enterprise/information";
import {
  listInfo,
  getQuotationInfo,
  saveQuotationProductMessage,
  updateQuotationProductMessage
} from "@/api/enterprise/quotation";
import { listMessage } from "@/api/enterprise/message";
import { listQualification } from "@/api/qualificationInfo/qualification";
import { getInfo } from "@/api/enterprise/info";
import { getElectric } from "@/api/electric/electric";
import { getSeas } from "@/api/highSeas/seas";
import { download } from "@/utils/request";
import { queryFile } from "@/api/system/file";
import { getToken } from "../../../utils/auth";
import { listType } from "@/api/maintype/type";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import pdf from "vue-pdf";
import Template from "../../membertemplate/index.vue";
import UploadFile from "../../upload/index.vue";
export default {
  name: "Information",
  components: {
    UploadFile,
    Template,
    pdf
  },
  dicts: [
    "business_classify",
    "customer_industry",
    "business_state",
    "tracking_stage",
    "enterprise_records",
    "product_type",
    "product_status",
    "customer_industry",
    "administrative_area",
    "qualification_resume_status",
    "business_source",
  ],
  props: {
    enterpriseId: {
      type: String,
      default: "",
    },
    enterpriseName: {
      type: String,
      default: "",
    },
  },
  data() {
    var approvalName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("审批人不能为空"));
      }
      return callback();
    };
    return {
      optBtn: false,
      isTree: false,
      uploadList: [],
      fileList: [],
      openFileList: false,
      qualificationCode: "qualification",
      openProduct: false,
      isTwoSave: false,
      customerId: null,
      typeContract: 0,
      dateRange: [],
      readonly: true,
      disabled: false,
      isSave: true,
      result: false,
      openPrint: false,
      openRecords: false,
      isDel: true,
      selectSwith: "",
      openMainClass: false,
      openEnterprise: false,
      titleClass: "修改主分类",
      optionData: null,
      isShow: false,
      userType: "1",
      sign: "1",
      newSign: "2",
      menuId: "2030",
      isClick: true,
      // 遮罩层
      loading: true,
      uploadId:null,
      UploadCode:null,
      // 选中数组
      ids: [],
      tableData: [],
      selectList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2: 0,
      // 【请填写功能名称】表格数据
      informationList: [],
      infoList: [],
      // 弹出层标题
      title: "",
      pageTotal: null,
      // 是否显示弹出层
      open: false,
      //主分类
      typeCode: "business",
      dialogVisible: false,
      dialogVisiblePdf: false,
      openQuotation: false,
      titleQuotation: "",
      dialogImageUrl: "",
      dialogImageUrlPdf: "",
      type: 0,
      number: 0,
      classId: "",
      eId: "",
      eName: "",
      // *********
      newApprovalNumber: null,
      newCompanyName: null,
      newEmployeeNumber: null,
      newAddress: null,
      newCertificateAuthority: null,
      newContacts: null,
      newPhone: null,
      newCustomerDemand: null,
      newUnit: null,
      newQuotationDescription: null,
      newPaymentMethod: null,
      newAfterService: null,
      newTips: null,
      newEnterpriseName: null,
      newEnterpriseAddress: null,
      newTelephone: null,
      pdfUrl: "",
      showIndex: 0,
      // 公海导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/business/information/importData",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        businessName: null,
        classificationId: null,
        enterpriseId: null,
        enterpriseName: null,
        businessState: null,
        businessType: null,
        businessSource: null,
        contacts: null,
        telephone: null,
        position: null,
        businessProvider: null,
        expectedDate: null,
        trackingStage: null,
        followPerson: null,
        developmentId: null,
        transactionId: null,
        developmentManager: null,
        businessManager: null,
        collaboratorId: null,
        collaboratorName: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        creationId: null,
        creationName: null,
      },
      queryContractProductParams: {
        pageNum: 1,
        pageSize: 5,
        productType: null,
        productNo: null,
        productName: null,
        productStatus: null,
        classificationId: null,
      },
      queryParamsMessage: {
        pageNum: 1,
        pageSize: 15,
        quotationId: null,
        systemType: null,
        fees: null,
        notes: null,
      },
      queryParamsQuotation: {
        pageNum: 1,
        pageSize: 15,
        businessId: null,
        approvalId: null,
        approvalNumber: null,
      },
      // 列信息
      columns: [
        { key: 0, label: `创建时间`, visible: true },
        { key: 1, label: `商机名称`, visible: true },
        { key: 2, label: `客户名称`, visible: true },
        { key: 3, label: `商机状态`, visible: true },
        { key: 4, label: `商机类型`, visible: true },
        { key: 5, label: `商机来源`, visible: true },
        { key: 6, label: `联系人姓名`, visible: true },
        { key: 7, label: `联系人电话`, visible: true },
        { key: 8, label: `联系人职位`, visible: true },
        { key: 9, label: `商机提供人`, visible: true },
        { key: 10, label: `预计成交时间`, visible: true },
        { key: 11, label: `创建人`, visible: true },
        { key: 12, label: `跟单阶段`, visible: true },
        { key: 13, label: `跟单人`, visible: true },
        { key: 14, label: `开发经理`, visible: true },
        { key: 15, label: `业务经理`, visible: true },
        { key: 16, label: `协作人`, visible: true },
        { key: 17, label: `附件`, visible: true },
        { key: 18, label: `最新操作时间`, visible: true },
        // { key: 19, label: `创建机构`, visible: true }
      ],
      // 表单参数
      form: {},
      formQuotation: {},
      formClass: {},
      formData: {},
      // 表单校验
      rules: {},
      rulesQuotation: {
        approvalInformation: [
          {
            max: 1000,
            message: "审批信息长度不能超过1000个字",
            trigger: "blur",
          },
        ],
        approvalResults: [
          { required: true, message: "审批结果不能为空", trigger: "blur" },
        ],
      },
      opt: "add",
      id: "",
      obj: null,
      index: null,
      newIndex: "",
      edit: "edit",
      uuid: "",
      qId: "",
      userId: "",
      cId: "",
      customName: "",
      liaison: "",
      telephoneNumber: "",
      customId: "",
      newBusinessId: "",
      isSame: true,
      businessCode: "businessinfo",
      productInfoList: [],
      qualificationList: [],
      productNames: [],
    };
  },
  created() {
    this.userId=this.$store.state.user.info.userId;
    console.log(this.userId,"多少")
    this.listType();
    this.getList();
    this.getProductList();
  },
  methods: {
    approveQuotation(row) {
      this.reset();
      this.disabled = false;
      this.isDel = true;
      this.isSave = true;
      this.isPrint = false;
      this.isTwoSave = false;
      this.form.businessId = row.businessId;
      this.newBusinessId = row.businessId;
      this.form.companyName = row.enterpriseName;
      this.form.companyId = row.enterpriseId;
      this.form.contacts = row.contacts;
      this.form.unit = row.telephone;
      this.customName = row.enterpriseName;
      this.customId = row.enterpriseId;
      this.liaison = row.contacts;
      this.telephoneNumber = row.telephone;
      getInfo(row.enterpriseId).then(response => {
        if (
          response.data.enterpriseAddress == null ||
          response.data.enterpriseAddress == ""
        ) {
          getSeas(row.enterpriseId).then(response => {
            if (
              response.data.enterpriseName == null ||
              response.data.enterpriseName == ""
            ) {
              getElectric(row.enterpriseId).then(response => {
                this.form.address = response.data.enterpriseAddress;
              });
            } else {
              this.form.address = response.data.enterpriseAddress;
            }
          });
        } else {
          this.form.address = response.data.enterpriseAddress;
        }
      });
      this.tableData = [];
      this.selectList = [];
      this.isShow = false;
      // this.selectList.push({ quotationId: "000000-00000-0000", approvalNumber: "新建立项编号" });
      this.qId = this.guid();
      this.titleQuotation = "报价单信息审核";
      this.openQuotation = true;
      this.queryParamsQuotation.businessId = row.businessId;
      this.queryParamsQuotation.approvalId = this.$store.state.user.info.userId;
      listInfo(this.queryParamsQuotation).then(response => {
        var data = response.rows;
        console.log(data)
        console.log(this.selectList)
        for (var i = 0; i < data.length; i++) {
          this.selectList.push({
            quotationId: data[i].quotationId,
            approvalNumber: data[i].approvalNumber,
          });
          if (this.selectList[i].quotationId === row.quotationId){
            this.selectSwith = this.selectList[i].approvalNumber;
            getQuotationInfo(this.selectList[i].quotationId).then(response => {
              this.reset();
              this.form = response.data;
              this.form.businessName = row.businessName;
              this.disabled = true;
              this.isDel = false;
              this.isSave = false;
              if (this.$store.state.user.name == this.form.approvalName) {
                this.isShow = true;
                this.isSave = true;
              } else {
                this.isShow = false;
              }
              if (this.form.approvalResults == "同意") {
                this.isPrint = true;
                this.isTwoSave = true;
              }
              if (
                this.form.approvalResults != null &&
                this.form.approvalResults != ""
              ) {
                this.result = true;
              }
              if (
                this.form.approvalResults == "同意" ||
                this.form.approvalResults == "不同意"
              ) {
                this.isSave = false;
              }
            });
            this.queryParamsMessage.quotationId = this.selectList[i].quotationId;
            listMessage(this.queryParamsMessage).then(response => {
              this.tableData = response.rows;
            });
          }
        }
      });
    },
    //下载
    handleDownload(fileUrl, fileName) {
      let params = {
        resource: fileUrl,
      };
      download("/common/download/resource", params, fileName);
    },
    handleView(row) {
      if (row.url != null && row.url != "" && row.url.indexOf(".pdf") !== -1) {
        this.handlePictureCardPreviewPdf(row.url);
      } else {
        this.handlePictureCardPreview(row.url);
      }
    },
    queryUploadFile(id) {
      queryFile(id, this.businessCode).then(response => {
        this.fileList = response.data;
        console.log(this.fileList);
      });
      this.openFileList = true;
    },
    carCheck(numbers) {
      this.qualificationList.forEach(item => {
        for (var j = 0; j < numbers.length; j++) {
          if (item.id == numbers[j].productId) {
            this.$refs.tableProduct.toggleRowSelection(item, true);
          }
        }
      });
    },

    getProductList() {
      this.loading = true;
      listQualification(this.queryContractProductParams).then(response => {
        this.qualificationList = response.rows;
        // var numbers = this.productInfoList;
        // setTimeout(() => {
        //     this.carCheck(numbers);
        // }, 300);
        this.total2 = response.total;
        this.loading = false;
      });
    },

    close() {
      this.$emit("change");
      this.type = 2;
      this.getList();
    },

    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      if (this.enterpriseId != null && this.enterpriseId != "") {
        this.queryParams.enterpriseId = this.enterpriseId;
      }
      listInformationReview(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then(response => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    listType() {
      listType({ typeCode: "business" }).then(res => {
        this.optionData = res.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    cancelClass() {
      this.openMainClass = false;
      this.resetClass();
    },
    // 表单重置
    resetClass() {
      this.formClass = {
        classificationId: null,
      };
    },
    reset() {
      this.form = {
        quotationId: null,
        businessId: null,
        approvalNumber: null,
        companyId: null,
        companyName: null,
        employeeNumber: null,
        address: null,
        certificateAuthority: null,
        contacts: null,
        customerDemand: null,
        unit: null,
        quotationDescription: null,
        paymentMethod: null,
        afterService: null,
        tips: null,
        approvalId: null,
        approvalName: null,
        approvalResults: null,
        approvalInformation: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.openRecords = false;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.classificationId = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.businessId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    handlePictureCardPreview(id, code) {
      this.uploadId = id;
      this.UploadCode = code;
      this.openFileList = true;
    },
    handlePictureCardPreviewPdf(url) {
      this.pdfUrl = pdf.createLoadingTask(url);
      // 获取页码
      this.pdfUrl.promise
        .then(pdf => (this.pageTotal = pdf.numPages))
        .catch(error => {});
      this.dialogImageUrlPdf = url;
      this.dialogVisiblePdf = true;
    },

    indexMethod(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    //索引初始化到对象
    tableRowClassName({ row, rowIndex }) {
      //把每一行的索引放进row
      row.index =
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize +
        rowIndex +
        1;
    },

    cancelQuotation() {
      this.openQuotation = false;
      this.tableData = [];
      this.selectList = [];
      this.result = false;
      this.reset();
    },

    /** 提交按钮 */
    submitFormQuotation() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          var tableList = this.tableData;
          for (var i = 0; i < tableList.length; i++) {
            if (
              tableList[i].systemType == "" ||
              tableList[i].systemType == null ||
              tableList[i].fees == "" ||
              tableList[i].fees == null ||
              tableList[i].notes == "" ||
              tableList[i].notes == null
            ) {
              this.$message.error("请完善报价单产品信息！");
              return;
            }
          }
          this.$confirm("保存后不能再修改报价单审批结果，是否继续？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              if (this.form.quotationId != null && this.isSame) {
                this.form["productMessageList"] = this.tableData;
                const data = this.form;
                updateQuotationProductMessage(data).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.openQuotation = false;
                  this.tableData = [];
                  this.getList();
                });
              } else {
                this.form.quotationId = this.qId;
                this.form["productMessageList"] = this.tableData;
                const data = this.form;
                saveQuotationProductMessage(data).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.openQuotation = false;
                  this.tableData = [];
                  this.getList();
                });
              }
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消保存",
              });
            });
        }
      });
    },
    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    },
    // 查看报价单（只读模式）
    viewQuotation(row) {
      this.reset();
      // 设置为只读状态
      this.disabled = true;
      this.isDel = false;
      this.isSave = false;
      this.isPrint = false;
      this.isTwoSave = false;

      this.form.businessId = row.businessId;
      this.newBusinessId = row.businessId;
      this.form.companyName = row.companyName || row.enterpriseName;
      this.form.companyId = row.enterpriseId;
      this.form.contacts = row.contacts;
      this.form.unit = row.telephone;
      this.customName = row.enterpriseName;
      this.customId = row.enterpriseId;
      this.liaison = row.contacts;
      this.telephoneNumber = row.telephone;
      this.form.businessName = row.businessName;

      // 获取企业地址
      getInfo(row.enterpriseId).then(response => {
        if (
          response.data.enterpriseAddress == null ||
          response.data.enterpriseAddress == ""
        ) {
          getSeas(row.enterpriseId).then(response => {
            if (
              response.data.enterpriseName == null ||
              response.data.enterpriseName == ""
            ) {
              getElectric(row.enterpriseId).then(response => {
                this.form.address = response.data.enterpriseAddress;
              });
            } else {
              this.form.address = response.data.enterpriseAddress;
            }
          });
        } else {
          this.form.address = response.data.enterpriseAddress;
        }
      });

      this.tableData = [];
      this.selectList = [];
      this.isShow = true; // 显示审批部分，但设为只读
      this.result = true; // 设置审批结果为只读

      this.titleQuotation = "查看报价单信息";
      this.openQuotation = true;

      // 获取报价单信息
      this.queryParamsQuotation.businessId = row.businessId;
      listInfo(this.queryParamsQuotation).then(response => {
        var data = response.rows;
        for (var i = 0; i < data.length; i++) {
          this.selectList.push({
            quotationId: data[i].quotationId,
            approvalNumber: data[i].approvalNumber,
          });
          if (this.selectList[i].quotationId === row.quotationId){
            this.selectSwith = this.selectList[i].approvalNumber;
            getQuotationInfo(this.selectList[i].quotationId).then(response => {
              this.form = response.data;
              // 确保所有表单字段为只读
              this.disabled = true;
              this.isDel = false;
              this.isSave = false;
            });
            this.queryParamsMessage.quotationId = this.selectList[i].quotationId;
            listMessage(this.queryParamsMessage).then(response => {
              this.tableData = response.rows;
            });
          }
        }
      });
    },
  },
};
</script>
